package com.wwj.controller.admin;

import com.wwj.common.result.PageResult;
import com.wwj.common.result.Result;
import com.wwj.pojo.dto.AdminOrderDTO;
import com.wwj.pojo.dto.CheckPageQueryDTO;
import com.wwj.pojo.dto.ReportDTO;
import com.wwj.pojo.dto.ReportPageQueryDTO;
import com.wwj.pojo.entity.Report;
import com.wwj.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("adminReportController")
@RequestMapping("/admin/report")
@Slf4j
@Api(tags="体检报告相关接口")
public class ReportController {

    @Resource
    private ReportService reportService;

    @PostMapping
    @ApiOperation(value = "生成报告")
    @CacheEvict(cacheNames = "ReportCache",allEntries = true)
    public Result insertReport(@RequestBody ReportDTO reportDTO){
        reportService.insertReport(reportDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "体检报告分页查询")
    public Result<PageResult> Page(ReportPageQueryDTO reportPageQueryDTO){

        PageResult pageResult= reportService.pageQuery(reportPageQueryDTO);

        return Result.success(pageResult);

    }

    @PutMapping
    @ApiOperation(value = "修改体检报告")
    @CacheEvict(cacheNames = "ReportCache",allEntries = true)
    public Result update(@RequestBody  ReportDTO reportDTO){
        reportService.update(reportDTO);
        return Result.success();
    }

    //删除体检项目
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除体检报告")
    @CacheEvict(cacheNames = "ReportCache",allEntries = true)
    public Result deleteReport(@PathVariable Long id){
        reportService.deleteReport(id);
        return Result.success();
    }
}
